package com.ihemou.system.feign.factory;

import com.ihemou.system.dto.SysSocialAppConfigDTO;
import com.ihemou.system.dto.SysUserDTO;
import com.ihemou.system.dto.WxUserInfoDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import com.ihemou.common.core.domain.R;
import com.ihemou.system.feign.RemoteUserService;
import com.ihemou.system.dto.UserInfo;

/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public R<UserInfo> getUserInfo(String username,String request)
            {
                return R.fail("获取用户失败:" + throwable.getMessage());
            }

            @Override
            public R<UserInfo> addSocialUser(WxUserInfoDTO wxUserInfoDTO,String request) {
                return R.fail("增加授权用户失败:" + throwable.getMessage());
            }

            @Override
            public R<SysSocialAppConfigDTO> getAppConfig(String appCode,String request) {
                return R.fail("获取小程序配置失败:" + throwable.getMessage());
            }

            @Override
            public R<UserInfo> findSocialUser(WxUserInfoDTO wxUserInfoDTO, String request) {
                return R.fail("授权用户登录失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> registerUserInfo(SysUserDTO sysUser, String request) {
                return R.fail("用户注册失败:" + throwable.getMessage());
            }
        };
    }
}
